import openpyxl
from openpyxl.drawing.image import Image
# 创建一个新的工作簿
wb = openpyxl.Workbook()

# 获取活动的工作表
ws = wb.active

# 设置标题
ws.append(["昵称", "手机号", "上传内容","图片","参与时间"])

# 写入示例数据
data = [
    ["张三", 28, "1995-03-15", fr"C:\Users\ASUS\Desktop\jianzhi\static\user_img\aLJCKm7A9TNu5efa675e9cb665271499ab44d9e41f01.jpg"],
    ["李四", 34, "1989-11-22", r"C:\Users\ASUS\Desktop\jianzhi\static\user_img\falsmncAZxXr302444d8f6ce90118ec449a56dc8b59a.jpg"],
    ["王五", 22, "2001-07-08", r"C:\Users\ASUS\Desktop\jianzhi\static\user_img\kWOTff03U9bf302444d8f6ce90118ec449a56dc8b59a.jpg"]
]

for row in data:
    ws.append(row[:3])  # 先添加前三列数据

# 插入图片
for idx, row in enumerate(data, start=2):
    img_path = row[3]
    img = Image(img_path)
    img.width = 100  # 设置图片宽度
    img.height = 100  # 设置图片高度Page({
    ws.add_image(img, f'D{idx}')  # 将图片插入到D列


wb.save("example.xlsx")
